<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>权限管理</title>
</head>
<body>
<script>
	$(function(){
		//打开查看员工权限详情界面
		$("#hwc-checkpower").linkbutton({
			onClick:function(){	
				var rows = $("#hwc-powerStaff").datagrid("getSelections");
				if(rows.length==0){
					$.messager.alert("提示","请选择一个员工！");
				}else if(rows.length >1 ){
					$.messager.alert("提示","一次只能编辑一个员工的权限！");
				}else{
					var staffNo = rows[0].staffNo;
						 $("#hwc-staffpowers").datagrid({
							url:'hwc_queryStaffPower',
							queryParams:{
								staffNo:staffNo
							}
						}); 
						$("#hwc-addstaffpowers").datagrid({
							url:'hwc_queryNotStaffPower',
							queryParams:{
								staffNo:staffNo
							}
						});
					$("#hwc-staffPowersWin").window("open");
				}
			}
		});
		
		//为员工添加权限
		$("#hwc-addpower").linkbutton({
			onClick:function(){
			
			//获取选中员工编号
			var rowsTwo = $("#hwc-powerStaff").datagrid("getSelections");
			var staffNo = rowsTwo[0].staffNo;
			
			//打开添加权限窗口	
			$("#hwc-addStaffPowersWin").window("open");
					//添加权限按钮
					$("#hwc-addpowerbtn").linkbutton({
						onClick:function(){
							var rows = $("#hwc-addstaffpowers").datagrid("getSelections");
							if(rows.length == 0){
								$.messager.alert("提示","您还未选择权限！");
							}else{
							$.messager.confirm("提示","您确定要添加该权限吗？",function(v){
								if(v){
									var arr = [];
									for(var i =0;i<rows.length;i++){
										arr.push(rows[i].powerNo);
									}
									//用<form>提交
									$("<form>").form('submit',{
										url:'hwc_addStaffPowers',
										onSubmit:function(param){
											param.list = arr;
										},
										queryParams:{	//传递员工编号
											staffNo:staffNo
										},
										 success:function(data){
											var json = eval("("+data+")");
											$.messager.alert("提示","权限添加成功！");
											$("#hwc-addstaffpowers").datagrid("reload");
											$("#hwc-staffpowers").datagrid("reload");
										} 
										
									});
								}
							});
						} //else括号	
					}
				});
			}
		});
		
		//移除员工的权限
		$("#hwc-movepower").linkbutton({
			onClick:function(){
				var rows =$("#hwc-staffpowers").datagrid("getSelections");
				var rowsTwo = $("#hwc-powerStaff").datagrid("getSelections");
				var staffNo = rowsTwo[0].staffNo;
				if(rows.length == 0){
					$.messager.alert("提示","您还未选择权限！");
				}else{
					$.messager.confirm("提示","您确定要移除该权限吗？",function(v){
						if(v){
							var arr = [];
							for(var i =0;i<rows.length;i++){
								arr.push(rows[i].powerNo);
							}
							//用<form>提交
							$("<form>").form('submit',{
								url:'hwc_delStaffPowers',
								onSubmit:function(param){
									param.list = arr;
								},
								queryParams:{	//传递员工编号
									staffNo:staffNo
								},
								 success:function(data){
									var json = eval("("+data+")");
									$.messager.alert("提示","权限删除成功！");
									$("#hwc-addstaffpowers").datagrid("reload");
									$("#hwc-staffpowers").datagrid("reload");
								} 
								
							});
						}
					});
				}
				
			}
			
		});
		//搜索权限
		$("#hwc-selectStaffPowers").searchbox({
			searcher:function(value){
				//获取之前选中的员工编号
				var staffRow = $("#hwc-powerStaff").datagrid("getSelections");
				var staffNo = staffRow[0].staffNo;
				
				$("#hwc-staffpowers").datagrid({
					url:'queryPowerGradeByPowers',
					method:'post',
					queryParams:{
						//将查询的字符以及员工编号传过去
						powerGrade:value,
						staffNo:staffNo
					},
					onLoadSuccess:function(){
						var rows = $("#hwc-staffpowers").datagrid("getRows");
						var row = rows[0];
						if(row == null){
							$.messager.alert("提示","不存在该关键字的权限！");
						}
					}
				});
				$(this).searchbox('setValue','');
			}
		});
		//搜索不属于该员工的权限
		$("#hwc-selectNotStaffPowers").searchbox({
			searcher:function(value){
				//获取之前选中的员工编号
				var staffRow = $("#hwc-powerStaff").datagrid("getSelections");
				var staffNo = staffRow[0].staffNo;
				$("#hwc-addstaffpowers").datagrid({
					url:'queryNotStaffNotPowers',
					method:'post',
					queryParams:{
						//将查询的字符以及员工编号传过去
						powerGrade:value,
						staffNo:staffNo
					},
					onLoadSuccess:function(){
						var rows = $("#hwc-addstaffpowers").datagrid("getRows");
						var row = rows[0];
						if(row == null){
							$.messager.alert("提示","不存在该关键字的权限！");
						}
					}
				});
				$(this).searchbox('setValue','');
			}
		});
		//显示全部
		$("#hwc-allstaffPower").linkbutton({
			onClick:function(){
				var staffRow = $("#hwc-powerStaff").datagrid("getSelections");
				var staffNo = staffRow[0].staffNo;
				$("#hwc-staffpowers").datagrid({
					url:'hwc_queryStaffPower',
					method:'get',
					queryOarams:{
						staffNo:staffNo
					}
				});	
				
			}
		});
		//显示全部不属于员工的权限
		$("#hwc-allNotStaffPower").linkbutton({
				onClick:function(){
					var staffRow = $("#hwc-powerStaff").datagrid("getSelections");
					var staffNo = staffRow[0].staffNo;
					$("#hwc-addstaffpowers").datagrid({
						url:'hwc_queryNotStaffPower',
						method:'get',
						queryOarams:{
							staffNo:staffNo
						}
					});
				}
		});
		//显示全部员工
		$("#hwc-allpower-staff").linkbutton({
			onClick:function(){
				$("#hwc-powerStaff").datagrid({
					url:'queryStaffByPageNoOut',
					method:'get',
				});	
			}
		});
		//搜索员工
		$("#hwc-selectPowerStaff").searchbox({
			searcher:function(value,name){
				$("#hwc-powerStaff").datagrid({
					url:name == 'select-staff-name' ? 'findStaffNameNoOutByPage':'finDeptNameNoOutByPage',
					method:'post',
					queryParams:{
						searche:value
					},
					onLoadSuccess:function(){
						var t = $("#hwc-powerStaff").datagrid("getRows");
						var d = t[0];
						if(d == null){
							$.messager.alert("提示","不存在该关键字的记录！");
						}
				}});
				$(this).searchbox('setValue','');
			}
		});
		
		
	});
</script>
	<!-- 界面员工 -->
	<table id="hwc-powerStaff" class="easyui-datagrid"
			data-options = " 
		url:'queryStaffByPageNoOut',
		fitColumns:true,
		fit:true,
		pagination:true,
		pageSize:5 ,
		pageList:[5,10,15,20],
		rownumbers:true,
		toolbar:'#hwc-powerthand',
		rownumbers:true,
		border:false
		">
		<thead>
			<tr>
				<th data-options="field:'staffNo',width:'1%', checkbox:true">员工编号</th>
				<th data-options="field:'staffName',width:'18%',align:'center'">姓名</th>
				<th data-options="field:'departmentName',width:'18%',align:'center'">所属科室</th>
				<th data-options="field:'staffAccount',width:'20%',align:'center'">账号</th>
				<th data-options="field:'postName',width:'15%',align:'center'">职务</th>
				<th data-options="field:'roleName',width:'18%',align:'center'">角色</th>
				<!-- <th data-options="field:'staffState',width:'14%',align:'center',
				styler:function(value,row,index){
					if(row.staffState == '离职'){
						return 'color:red;';
					}	
				}	
				">状态</th> -->
				<th data-options="field:'titleName',width:'10%',align:'center',required:true">职称</th>
				
			</tr>
		</thead>
		
	</table>
	
	<!-- 界面菜单按钮 -->
	<div	id="hwc-powerthand">
		<a id="hwc-checkpower" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">查看权限</a>
		<a id="hwc-allpower-staff" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">全部员工</a>
		<input id="hwc-selectPowerStaff"	class="easyui-searchbox" data-options="prompt:'输入关键字 搜索',menu:'#hwc-powerthandmenu'" style="width:250px">
	</div>
	<!-- 界面菜单搜索按钮DIV -->
	<div id="hwc-powerthandmenu">
		<div name="select-staff-name">姓名</div>
		<div name="select-staff-dept">科室</div>
		<!-- <div name="select-staff-post">职务</div>
		<div name="select-staff-role">角色</div> -->
	</div>
	<!-- 查看用户权限 -->
	<div id="hwc-staffPowersWin" class="easyui-window" title="权限详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:280px;height:310px;padding:5px;">
		<!-- <div class="easyui-layout" data-options="fit:true"> -->
		<div class="easyui-layout" data-options="fit:true"> 
			<div id="hwc-power-panel" class="easyui-panel" data-options="region:'center'"  style="padding:0px;">
				<!-- 显示该员工的权限集合 -->
				<table id="hwc-staffpowers" class="easyui-datagrid" data-options = " 
					fitColumns:true,
					fit:true,
					rownumbers:true,
					toolbar:'#hwc-staffPowersWinHand',
					border:false">
					<thead>
						<tr>
							<th data-options="field:'powerNo',width:'1%', checkbox:true">权限编号</th>
							<th data-options="field:'powerGrade',width:'40',align:'center'">权限名称</th>
						</tr>
					</thead>
				</table>
			</div>
			<!-- 关闭按钮 -->
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<!-- <a id="hwc-power-okbtn" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >确定</a> -->
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#hwc-staffPowersWin').window('close');" onclick="">关闭</a>
			</div>
		</div>
	</div>
	<!-- 权限详情表头按钮 -->
	<div id="hwc-staffPowersWinHand">
		<div>
			<a id="hwc-addpower" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="width:49%">添加权限</a>
			<a id="hwc-movepower" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" style="width:49%">移除权限</a>
		</div>
		<div>
			<input id="hwc-selectStaffPowers"	class="easyui-searchbox" data-options="prompt:'搜索权限'" style="width:75%">
			<a id="hwc-allstaffPower" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:22%">全部</a>
			<!--  <a id="hwc-allpower" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:15%">全部</a>-->
		</div>
	</div>
	
	
	<!-- 添加用户所没有的权限窗口 -->
	<div id="hwc-addStaffPowersWin" class="easyui-window" title="添加权限" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:280px;height:300px;padding:5px;">
		<!-- <div class="easyui-layout" data-options="fit:true"> -->
		<div class="easyui-layout" data-options="fit:true"> 
			<div id="hwc-addpower-panel" class="easyui-panel" data-options="region:'center'"  style="padding:0px;">
				<!-- 显示该员工的权限集合 -->
				<table id="hwc-addstaffpowers" class="easyui-datagrid" data-options = " 
					fitColumns:true,
					fit:true,
					rownumbers:true,
					toolbar:'#selectPowersDiv',
					border:false">
					<thead>
						<tr>
							<th data-options="field:'powerNo',width:'1%', checkbox:true">权限编号</th>
							<th data-options="field:'powerGrade',width:'40',align:'center'">权限名称</th>
						</tr>
					</thead>
				
				</table>
				
			</div>
			
			<!-- 按钮 -->
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="hwc-addpowerbtn" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >添加</a> 
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#hwc-addStaffPowersWin').window('close');" onclick="">关闭</a>
			</div>
		</div>
	</div>
	<div id="selectPowersDiv">
		<input id="hwc-selectNotStaffPowers"	class="easyui-searchbox" data-options="prompt:'搜索权限'" style="width:75%">
		<a id="hwc-allNotStaffPower" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:22%">全部</a>
	</div>
</body>
</html>